package org.wjw.auth.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wjw.auth.WjwPermission;
import org.wjw.auth.domain.Permission;
import org.wjw.auth.service.IPermissionService;
import org.wjw.base.util.AjaxResult;
import org.wjw.dto.accept.ResultDTO;
import org.wjw.base.query.BaseQuery;

import java.util.List;

@RestController
@WjwPermission(name="权限管理",desc = "这是权限管理")
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    IPermissionService permissionService;

    @PostMapping
    @WjwPermission(name="分页查询权限",desc = "这是分页查询权限")
    public AjaxResult getPermissionPage(@RequestBody BaseQuery queryVo){
        try {
            ResultDTO<Permission> result=permissionService.getAllPage(queryVo);
            return new AjaxResult().getself().setObj(result);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("分页查出错"+e.getMessage());
        }
    }


    @GetMapping("/tree")
    @WjwPermission(name="获取权限树",desc = "这是获取权限树")
    public AjaxResult getPermissionTree(){
        try {
            List<Permission> permissions=permissionService.getPermissionTree();
            return new AjaxResult().getself().setObj(permissions);

        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("获取权限树失败"+e.getMessage());
        }
    }


    @GetMapping("/sns")
    public AjaxResult getPermisionSns(){
        try {
            List<String> permisionSns = permissionService.getPermisionSns();
            return AjaxResult.getself().setObj(permisionSns);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getself().setSuccess(false).setMessage("权限树查询失败!"+e.getMessage());
        }
    }
}
